//
//  PackageDetailRecommandCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/8/2.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "PackageDetailRecommandCell.h"

@implementation PackageDetailRecommandCell

+ (CGFloat)calculateHeight {
    return 200;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    self.fanxianLab.layer.backgroundColor = UIColorHex(0xffeee0).CGColor;
    self.fanxianLab.layer.cornerRadius = 3;
    
}

- (void)fillCellWithModel:(CommonPackageModel *)model {
    
    NSString *url = [TT_OSSManager reSourceUrl:model.hengUrl type:BA_resizeType_pro];
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.mainTitleLab.text = model.goodsName;
    
        self.activityPriceLab.text =[NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:model.goodsActivePrice]];
        
        if (model.goodsTotal > 0) {
            NSDictionary*attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
            NSMutableAttributedString*attribtStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:model.goodsTotal]] attributes:attribtDic];// 赋值strikeLabel.attributedText=
            self.linePriceLab.attributedText = attribtStr;
            self.linePriceLab.hidden = NO;

            
            double packageCommission = [BA_BusinessHelper shared].userProportion*0.01;
            double tax = [BA_BusinessHelper shared].taxPoint *0.01;

            NSString *doubleStr = [NSString stringWithFormat:@"%.0f",model.goodsActivePrice*packageCommission*(1-tax)];
            NSDecimalNumber *dn = [NSDecimalNumber decimalNumberWithString:doubleStr];
            self.fanxianLab.text = [NSString stringWithFormat:@"  ¥%@ ",dn.stringValue];
            self.fanxianLab.hidden = NO;
            self.fanxianIcon.hidden = NO;
            
            if (packageCommission == 0) {
                self.fanxianLab.hidden = YES;
                self.fanxianIcon.hidden = YES;
            }
            
            self.activityPriceLab.text = [NSString stringWithFormat:@"¥%@",[Utilities changeDoubleToString:model.goodsActivePrice]];

            
        } else {
            self.linePriceLab.hidden = YES;
        }
    
    self.fanxianLab.hidden = YES;
    self.fanxianIcon.hidden = YES;
    self.linePriceLab.hidden = YES;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.mainImageView pp_clipCorners:UIRectCornerAllCorners radius:6];
    });
}

@end
